package com.equipment.management.service.impl;

import com.equipment.management.dao.FloorDao;
import com.equipment.management.entity.Floor;
import com.equipment.management.service.FloorService;
import com.equipment.management.util.Base64Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/16.
 */
@Slf4j
@Service(value = "floorService")
public class FloorServiceImpl extends Base64Util implements FloorService {

    @Autowired
    private FloorDao floorDao;//这里会报错，但是并不会影响

    /*
    * 这个方法中用到了我们开头配置依赖的分页插件pagehelper
    * 很简单，只需要在service层传入参数，然后将参数传递给一个插件的一个静态方法即可；
    * pageNum 开始页数
    * pageSize 每页显示的数据条数
    * */
    @Override
    public List<Map> findAllFloor(Integer floor_level) {

        List<Map> floorDomains = floorDao.selectFloors(floor_level);
        return floorDomains;
    }

    @Override
    public Floor getFloorByMessage(String name, String password) throws Exception {

        Floor us = floorDao.getFloorByMessage(name, encrypt(password));
        return us;
    }


    @Override
    public int addFloor(Floor floor) throws Exception {
        floor.setState(1);//1=true,0=false
        floor.setCreate_time(new Date());
        log.info("楼层参数：{}",floor);
        return floorDao.addFloor(floor);
    }

    @Override
    public int deleteFloor(int id) {
        int i = floorDao.deleteFloor(id);
        return i;
    }

    @Override
    public Floor getFloorByLevel(int floor_level) {
        Floor us = floorDao.getFloorByLevel(floor_level);
        return us;
    }


}
